/*
 * Applet1.java
 *
 * Created on 17. �erven 2007, 21:27
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package cz.possoft.client.gui.applet;

//<applet code=Applet1 width=100 height=50>
//</applet>
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JLabel;

import cz.possoft.client.gui.panel.nastavenispodnipanel.panel.NastaveniShowPanel;
import cz.possoft.client.threads.DialogThread;

public class ShowApplet extends JApplet {
    
    public void init() {
        getContentPane().add(new JLabel("zdarec"));
    }

    public static JApplet runApplet(String appletName, int width, int height, String frameLabel) {

        class MyWindowListener extends WindowAdapter {
            
            public void windowClosing(WindowEvent e) {
                if (NastaveniShowPanel.getConnectThread() != null) {
                    NastaveniShowPanel.getConnectThread().sendToServer("CLOSE: ");
                }
                //System.out.println("Udalost windowClosing nastala.");
                System.exit(0);
            }

            
            public void windowActivated(WindowEvent e) {
            	DialogThread.controlDialogs();
            }
        }

        JApplet applet = new JApplet();
        try {
            Class c = Class.forName(appletName);
            applet = (JApplet) (c.newInstance());
            JFrame frame = new JFrame(frameLabel);
            frame.getContentPane().add(applet);
            frame.setBounds(100, 0, width, height);
            applet.init();
            applet.start();
            frame.addWindowListener(new MyWindowListener());
            frame.setVisible(true);
        } catch (InstantiationException e) {
            System.err.println("Instantiation exception: ");
            e.printStackTrace();
        } catch (ClassNotFoundException e2) {
            System.err.println("ClassNotFound Exception: ");
            e2.printStackTrace();
        } catch (IllegalAccessException e3) {
            System.err.println("IllegalAccessException: ");
            e3.printStackTrace();
        } catch (Exception ex) {
            System.out.println("nejaka exception");
            ex.printStackTrace();
        } finally {
            return applet;
        }
    }

    public static void main(String[] args) {
        runApplet("cz.possoft.client.gui.applet.ShowApplet", 500, 50, "Nadpis ramce");
    }
}